<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="Generator" content="iWeb 3.0.4"/>
<meta name="iWeb-Build" content="local-build-20161221"/>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
<meta name="viewport" content="width=770"/>
<title>wolfSSL - Docs | wolfSSL Manual - Chapter 11 (SSL Tutorial)</title>
<link rel="stylesheet" type="text/css" media="screen,print" href="Docs-wolfssl-manual-11-ssl-tutorial_files/Docs-wolfssl-manual-11-ssl-tutorial.css"/>
<!--[if lt IE 8]><link rel='stylesheet' type='text/css' media='screen,print' href='Docs-wolfssl-manual-11-ssl-tutorial_files/Docs-wolfssl-manual-11-ssl-tutorialIE.css'/><![endif]-->
<!--[if gte IE 8]><link rel='stylesheet' type='text/css' media='screen,print' href='Media/IE8.css'/><![endif]-->
<script type="text/javascript" src="Scripts/iWebSite.js"></script>
<script type="text/javascript" src="Scripts/iWebImage.js"></script>
<script type="text/javascript" src="Docs-wolfssl-manual-11-ssl-tutorial_files/Docs-wolfssl-manual-11-ssl-tutorial.js"></script>
<meta name="description" content="A tutorial explaining how to add SSL/TLS support into an existing application using the wolfSSL embedded SSL library (formerly CyaSSL)."/><meta name="keywords" content="embedded ssl, ssl library, ssl tutorial, ssl programming tutorial, tls 1.2, dtls, echoserver, echoclient, unix network programming, richard stevens, bill fenner, andrew rudoff, small openssl, smart grid, connected home, ecc, lightweight ssl, suite b, encryption security software, ssl inspection"/><meta name="robots" content="follow,index"/> <!--ipt>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create','UA-64826966-1','auto');ga('send','pageview');</scri-->
 
<script>//<![CDATA[
window.zEmbed||function(e,t){var n,o,d,i,s,a=[],r=document.createElement("iframe");window.zEmbed=function(){a.push(arguments)},window.zE=window.zE||window.zEmbed,r.src="javascript:false",r.title="",r.role="presentation",(r.frameElement||r).style.cssText="display: none",d=document.getElementsByTagName("script"),d=d[d.length-1],d.parentNode.insertBefore(r,d),i=r.contentWindow,s=i.document;try{o=s}catch(c){n=document.domain,r.src='javascript:var d=document.open();d.domain="'+n+'";void(0);',o=s}o.open()._l=function(){var o=this.createElement("script");n&&(this.domain=n),o.id="js-iframe-async",o.src=e,this.t=+new Date,this.zendeskHost=t,this.zEQueue=a,this.body.appendChild(o)},o.write('<body onload="document._l();">'),o.close()}("../../https@assets.zendesk.com/embeddable_framework/main.js","wolfssl.zendesk.com");
//]]></script>
  </head>
<body style="background: rgb(255, 255, 255); margin: 0pt; " onload="onPageLoad();">
<div style="text-align: center; ">
<div style="margin-bottom: 20px; margin-left: auto; margin-right: auto; margin-top: 20px; overflow: hidden; position: relative; word-wrap: break-word;  background: rgb(255, 255, 255); text-align: left; width: 770px; " id="body_content">
<div style="float: left; margin-left: 0px; position: relative; width: 770px; z-index: 0; " id="nav_layer">
<div style="height: 0px; line-height: 0px; " class="bumper"> </div>
<div style="clear: both; height: 0px; line-height: 0px; " class="spacer"> </div>
</div>
<div style="float: left; height: 0px; line-height: 0px; margin-left: 0px; position: relative; width: 770px; z-index: 10; " id="header_layer">
<div style="height: 0px; line-height: 0px; " class="bumper"> </div>
</div>
<div style="margin-left: 0px; position: relative; width: 770px; z-index: 5; " id="body_layer">
<div style="height: 0px; line-height: 0px; " class="bumper"> </div>
<div id="id1" style="height: 38px; left: 375px; position: absolute; top: 157px; width: 361px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_361_38" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style">wolfSSL Manual</p>
</div>
</div>
</div>
<div id="id2" style="height: 317px; left: 35px; position: absolute; top: 281px; width: 701px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_701_317" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-top: 0pt; " class="paragraph_style_1">Chapter 11: SSL Tutorial<span class="style"><br/></span></p>
<p class="paragraph_style_2"><br/></p>
<p class="paragraph_style_3"><br/></p>
<p class="paragraph_style_3">11.1 Introduction<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">The wolfSSL (formerly CyaSSL) embedded SSL library can easily be integrated into your existing application or device to provide enhanced communication security through the addition of SSL and TLS. wolfSSL has been targeted at embedded and RTOS environments, and as such, offers a minimal footprint while maintaining excellent performance. Minimum build sizes for wolfSSL range between 20-100kB depending on the selected build options and platform being used.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">The goal of this tutorial is to walk through the integration of SSL and TLS into a simple application. Hopefully the process of going through this tutorial will also lead to a better understanding of SSL in general. This tutorial uses wolfSSL in conjunction with simple echoserver and echoclient examples to keep things as simple as possible while still demonstrating the general procedure of adding SSL support to an application. The echoserver and echoclient examples have been taken from the popular book titled “<span class="style_1">Unix Network Programming, Volume 1, 3rd Edition</span>” by Richard Stevens, Bill Fenner, and Andrew Rudoff.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p style="padding-bottom: 0pt; " class="paragraph_style_4">This tutorial assumes that the reader is comfortable with editing and compiling C code using the GNU GCC compiler as well as familiar with the concepts of public key encryption. Please note that access to the Unix Network Programming book is not required for this tutorial.</p>
</div>
</div>
</div>
<div id="id3" style="height: 24px; left: 193px; position: absolute; top: 122px; width: 268px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_268_24" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_5"><a class="class1" title="Docs.html" href="Docs.html">Docs</a> <span class="style_2">-&gt;</span> <span class="style_3">wolfSSL Manual</span></p>
</div>
</div>
</div>
<div style="height: 1px; width: 698px;  height: 1px; left: 37px; position: absolute; top: 220px; width: 698px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 698px; ">
<img src="Docs-wolfssl-manual-11-ssl-tutorial_files/shapeimage_1.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 698px; "/>
</div>
</div>
<div style="height: 37px; width: 545px;  height: 37px; left: 191px; position: absolute; top: 80px; width: 545px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 545px; ">
<img src="Docs-wolfssl-manual-11-ssl-tutorial_files/shapeimage_2.png" alt="" style="height: 37px; left: 0px; position: absolute; top: 0px; width: 545px; "/>
</div>
</div>
<div id="id4" style="height: 25px; left: 200px; position: absolute; top: 84px; width: 43px; z-index: 1; " class="style_SkipStroke_1 shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_43_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_6"><a class="class2" title="Home.html" href="Home.html">Home</a></p>
</div>
</div>
</div>
<div id="id5" style="height: 25px; left: 365px; position: absolute; top: 84px; width: 72px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_72_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_7"><a class="class3" title="https://wolfssl.com/wolfSSL/download/downloadForm.php" href="../../https@wolfssl.com/wolfSSL/download/downloadForm.php">Download</a></p>
</div>
</div>
</div>
<div id="id6" style="height: 25px; left: 439px; position: absolute; top: 84px; width: 59px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_59_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_7"><a class="class4" title="License.html" href="License.html">License</a></p>
</div>
</div>
</div>
<div id="id7" style="height: 25px; left: 499px; position: absolute; top: 84px; width: 44px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_44_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_7"><a class="class5" title="Blog/Blog.html" href="Blog/Blog.html">Blog</a></p>
</div>
</div>
</div>
<div id="id8" style="height: 25px; left: 589px; position: absolute; top: 84px; width: 80px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_80_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_7"><a class="class6" title="Community.html" href="Community.html">Community</a></p>
</div>
</div>
</div>
<div style="height: 36px; width: 1px;  height: 36px; left: 245px; position: absolute; top: 81px; width: 0px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 0px; ">
<img src="Docs-wolfssl-manual-11-ssl-tutorial_files/shapeimage_3.png" alt="" style="height: 36px; left: 0px; position: absolute; top: 0px; width: 1px; "/>
</div>
</div>
<div style="height: 37px; width: 1px;  height: 37px; left: 296px; position: absolute; top: 80px; width: 0px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 0px; ">
<img src="Docs-wolfssl-manual-11-ssl-tutorial_files/shapeimage_4.png" alt="" style="height: 37px; left: 0px; position: absolute; top: 0px; width: 1px; "/>
</div>
</div>
<div style="height: 36px; width: 1px;  height: 36px; left: 363px; position: absolute; top: 81px; width: 0px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 0px; ">
<img src="Docs-wolfssl-manual-11-ssl-tutorial_files/shapeimage_5.png" alt="" style="height: 36px; left: 0px; position: absolute; top: 0px; width: 1px; "/>
</div>
</div>
<div style="height: 36px; width: 1px;  height: 36px; left: 438px; position: absolute; top: 81px; width: 0px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 0px; ">
<img src="Docs-wolfssl-manual-11-ssl-tutorial_files/shapeimage_6.png" alt="" style="height: 36px; left: 0px; position: absolute; top: 0px; width: 1px; "/>
</div>
</div>
<div style="height: 37px; width: 1px;  height: 37px; left: 498px; position: absolute; top: 80px; width: 0px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 0px; ">
<img src="Docs-wolfssl-manual-11-ssl-tutorial_files/shapeimage_7.png" alt="" style="height: 37px; left: 0px; position: absolute; top: 0px; width: 1px; "/>
</div>
</div>
<div style="height: 37px; width: 1px;  height: 37px; left: 589px; position: absolute; top: 80px; width: 0px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 0px; ">
<img src="Docs-wolfssl-manual-11-ssl-tutorial_files/shapeimage_8.png" alt="" style="height: 37px; left: 0px; position: absolute; top: 0px; width: 1px; "/>
</div>
</div>
<div id="id9" style="height: 25px; left: 671px; position: absolute; top: 84px; width: 61px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_61_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_7"><a class="class7" title="Contact.html" href="Contact.html">Contact</a></p>
</div>
</div>
</div>
<div id="id10" style="height: 25px; left: 249px; position: absolute; top: 84px; width: 44px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_44_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_6"><a class="class8" title="About.html" href="About.html">About</a></p>
</div>
</div>
</div>
<div style="height: 36px; width: 1px;  height: 36px; left: 670px; position: absolute; top: 81px; width: 0px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 0px; ">
<img src="Docs-wolfssl-manual-11-ssl-tutorial_files/shapeimage_9.png" alt="" style="height: 36px; left: 0px; position: absolute; top: 0px; width: 1px; "/>
</div>
</div>
<div id="id11" style="height: 25px; left: 298px; position: absolute; top: 84px; width: 63px; z-index: 1; " class="style_SkipStroke_1 shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_63_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_7"><a class="class9" title="Products.html" href="Products.html">Products</a></p>
</div>
</div>
</div>
<div id="id12" style="height: 25px; left: 549px; position: absolute; top: 84px; width: 41px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_41_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_6"><a class="class10" title="Docs.html" href="Docs.html">Docs</a></p>
</div>
</div>
</div>
<div style="height: 37px; width: 1px;  height: 37px; left: 545px; position: absolute; top: 80px; width: 0px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 0px; ">
<img src="Docs-wolfssl-manual-11-ssl-tutorial_files/shapeimage_10.png" alt="" style="height: 37px; left: 0px; position: absolute; top: 0px; width: 1px; "/>
</div>
</div>
<div id="id13" style="height: 27px; left: 634px; position: absolute; top: 224px; width: 102px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_102_27" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_8"><a class="class11" title="Docs-wolfssl-manual-12-best-practices-for-embedded-devices.html" href="Docs-wolfssl-manual-12-best-practices-for-embedded-devices.html">Next Chapter</a></p>
</div>
</div>
</div>
<div id="id14" style="height: 25px; left: 35px; position: absolute; top: 224px; width: 125px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_125_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_9"><a class="class12" title="Docs-wolfssl-manual-10-wolfcrypt-usage-reference.html" href="Docs-wolfssl-manual-10-wolfcrypt-usage-reference.html">Previous Chapter</a></p>
</div>
</div>
</div>
<div id="id15" style="height: 27px; left: 59px; position: absolute; top: 190px; width: 196px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_196_27" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_10"><a class="class13" title="https://www.wolfssl.com/documentation/wolfSSL-Manual.pdf" href="../documentation/wolfSSL-Manual.pdf">Download wolfSSL Manual (PDF)</a></p>
</div>
</div>
</div>
<div style="height: 22px; width: 22px;  height: 22px; left: 33px; position: absolute; top: 191px; width: 22px; z-index: 1; " class="tinyText style_SkipStroke_2">
<img src="Docs-wolfssl-manual-11-ssl-tutorial_files/PDF.png" alt="" style="border: none; height: 22px; width: 22px; "/>
</div>
<div id="id16" style="height: 202px; left: 40px; position: absolute; top: 645px; width: 687px; z-index: 1; " class="style_SkipStroke_3 shape-with-text stroke_0">
<div class="text-content graphic_shape_layout_style_default_External_685_200" style="padding: 1px; ">
<div class="graphic_shape_layout_style_default"></div>
</div>
</div>
<div id="id17" style="height: 60px; left: 226px; position: absolute; top: 744px; width: 238px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_238_60" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-top: 0pt; " class="paragraph_style_11"><span class="style_4">Examples Used in this Tutorial<br/></span></p>
<p class="paragraph_style_12"><span class="style_5">echoclient</span> - Figure 5.4, Page 124<br/></p>
<p style="padding-bottom: 0pt; " class="paragraph_style_12"><span class="style_5">echoserver</span> - Figure 5.12, Page 139</p>
</div>
</div>
</div>
<div style="height: 168px; width: 134px;  height: 168px; left: 60px; position: absolute; top: 662px; width: 134px; z-index: 1; " class="tinyText style_SkipStroke_2">
<img src="Docs-wolfssl-manual-11-ssl-tutorial_files/unpbook.png" alt="" style="border: none; height: 168px; width: 135px; "/>
</div>
<div id="id18" style="height: 68px; left: 225px; position: absolute; top: 664px; width: 300px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_300_68" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-top: 0pt; " class="paragraph_style_13"><span class="style_4">Unix Network Programming</span><span class="style_5"><br/></span></p>
<p class="paragraph_style_12"><span class="style_4">Volume 1, 3rd Edition<br/></span></p>
<p style="padding-bottom: 0pt; " class="paragraph_style_12"><a class="class14" title="http://www.unpbook.com" href="../../www.unpbook.com/default.htm">www.unpbook.com</a></p>
</div>
</div>
</div>
<div id="id19" style="height: 9216px; left: 35px; position: absolute; top: 886px; width: 700px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_700_9216" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-top: 0pt; " class="paragraph_style_3">11.2 Quick Summary of SSL/TLS<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><span class="style_1">TLS</span> (Transport Layer Security) and <span class="style_1">SSL</span> (Secure Sockets Layer) are cryptographic protocols that allow for secure communication across a number of different transport protocols.  The primary transport protocol used is TCP/IP. The most recent version of SSL/TLS is TLS 1.2. wolfSSL supports SSL 3.0, TLS 1.0, 1.1, and 1.2 in addition to DTLS 1.0 and 1.2.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">SSL and TLS sit between the Transport and Application layers of the OSI model, where any number of protocols (including TCP/IP, Bluetooth, etc.) may act as the underlying transport medium. Application protocols are layered on top of SSL and can include protocols such as HTTP, FTP, and SMTP. A diagram of how SSL fits into the OSI model, as well as a simple diagram of the SSL handshake process can be found in <a title="Docs-wolfssl-manual-A-ssl-tls-overview.html" href="Docs-wolfssl-manual-A-ssl-tls-overview.html">Appendix A</a>.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_3">11.3 Getting the Source Code<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">All of the source code used in this tutorial can be downloaded from the wolfSSL website, specifically from the following location. The download contains both the original and completed source code for both the echoserver and echoclient used in this tutorial. Specific contents are listed below the link.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><a title="http://www.wolfssl.com/documentation/ssl-tutorial-2.2.zip" href="../../www.wolfssl.com/documentation/ssl-tutorial-2.2.zip">http://www.wolfssl.com/documentation/ssl-tutorial-2.2.zip</a><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">The downloaded ZIP file has the following structure:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">The downloaded ZIP file has the following structure:<br/></p>
<p class="paragraph_style_14">/include<br/></p>
<p class="paragraph_style_14">    (Common header file [Modified from unp.h in the book])<br/></p>
<p class="paragraph_style_14">/lib<br/></p>
<p class="paragraph_style_14">    (Common library functions)<br/></p>
<p class="paragraph_style_14">/finished_src<br/></p>
<p class="paragraph_style_14">    /echoclient<br/></p>
<p class="paragraph_style_14">        (The completed echoclient code)<br/></p>
<p class="paragraph_style_14">    /echoserver<br/></p>
<p class="paragraph_style_14">        (The completed echoserver code)<br/></p>
<p class="paragraph_style_14">/original_src<br/></p>
<p class="paragraph_style_14">    /echoclient<br/></p>
<p class="paragraph_style_14">        (The starting echoclient code)<br/></p>
<p class="paragraph_style_14">    /echoserver<br/></p>
<p class="paragraph_style_14">        (The starting echoserver code)<br/></p>
<p class="paragraph_style_14">wolfSSL_SSL_Tutorial.pdf<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_3">11.4 Base Example Modifications<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">This tutorial, and the source code that accompanies it, have been designed to be as portable as possible across platforms. Because of this, and because we want to focus on how to add SSL and TLS into an application, the base examples have been kept as simple as possible. Several modifications have been made to the examples taken from Unix Network Programming in order to either remove unnecessary complexity or increase the range of platforms supported. If you believe there is something we could do to increase the portability of this tutorial, please let us know at <a title="mailto:support@wolfssl.com" href="../cdn-cgi/l/email-protection#dba8aeababb4a9af9bacb4b7bda8a8b7f5b8b4b6"><span class="__cf_email__" data-cfemail="9be8eeebebf4e9efdbecf4f7fde8e8f7b5f8f4f6">[email&#160;protected]</span><script data-cfhash='f9e31' type="text/javascript">/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */</script></a>.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">The following is a list of modifications that were made to the original echoserver and echoclient examples found in the above listed book.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_15">Modifications to the echoserver (tcpserv04.c)<br/></p>
<p class="paragraph_style_4"><br/></p>
<ol>
<li style="line-height: 15px; margin-top: -1px; padding-left: 30px; text-indent: -15px; " class="full-width">
<p style="text-indent: -15px; " class="paragraph_style_16"><span style="font-size: 20px; position: relative; top: 3px; " class="Bullet">•</span><span style="width: 8px; " class="inline-block"></span>Removed call to the Fork() function because fork() is not supported by Windows. The result of this is an echoserver which only accepts one client simultaneously. Along with this removal, Signal handling was removed.<br/></p>
</li>
</ol>
<p class="paragraph_style_17"><br/></p>
<ol>
<li style="line-height: 15px; margin-top: -1px; padding-left: 30px; text-indent: -15px; " class="full-width">
<p style="text-indent: -15px; " class="paragraph_style_16"><span style="font-size: 20px; position: relative; top: 3px; " class="Bullet">•</span><span style="width: 8px; " class="inline-block"></span>Moved str_echo() function from str_echo.c file into tcpserv04.c file<br/></p>
</li>
</ol>
<p class="paragraph_style_17"><br/></p>
<ol>
<li style="line-height: 15px; margin-top: -1px; padding-left: 30px; text-indent: -15px; " class="full-width">
<p style="text-indent: -15px; " class="paragraph_style_16"><span style="font-size: 20px; position: relative; top: 3px; " class="Bullet">•</span><span style="width: 8px; " class="inline-block"></span>Added a printf statement to view the client address and the port we have connected through:<br/></p>
</li>
</ol>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    printf(&quot;Connection from %s, port %d\n&quot;,<br/></p>
<p class="paragraph_style_14">           inet_ntop(AF_INET, &amp;cliaddr.sin_addr, buff, sizeof(buff)),<br/></p>
<p class="paragraph_style_14">           ntohs(cliaddr.sin_port));<br/></p>
<p class="paragraph_style_4"><br/></p>
<ol>
<li style="line-height: 15px; margin-top: -1px; padding-left: 30px; text-indent: -15px; " class="full-width">
<p style="text-indent: -15px; " class="paragraph_style_16"><span style="font-size: 20px; position: relative; top: 3px; " class="Bullet">•</span><span style="width: 8px; " class="inline-block"></span>Added a call to setsockopt() after creating the listening socket to eliminate the “Address already in use” bind error.<br/></p>
</li>
</ol>
<p class="paragraph_style_17"><br/></p>
<ol>
<li style="line-height: 15px; margin-top: -1px; padding-left: 30px; text-indent: -15px; " class="full-width">
<p style="text-indent: -15px; " class="paragraph_style_16"><span style="font-size: 20px; position: relative; top: 3px; " class="Bullet">•</span><span style="width: 8px; " class="inline-block"></span>Minor adjustments to clean up newer compiler warnings<br/></p>
</li>
</ol>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_15">Modifications to the echoclient (tcpcli01.c)<br/></p>
<p class="paragraph_style_4"><br/></p>
<ol>
<li style="line-height: 15px; margin-top: -1px; padding-left: 30px; text-indent: -15px; " class="full-width">
<p style="text-indent: -15px; " class="paragraph_style_16"><span style="font-size: 20px; position: relative; top: 3px; " class="Bullet">•</span><span style="width: 8px; " class="inline-block"></span>Moved str_cli() function from str_cli.c file into tcpcli01.c file<br/></p>
</li>
</ol>
<p class="paragraph_style_17"><br/></p>
<ol>
<li style="line-height: 15px; margin-top: -1px; padding-left: 30px; text-indent: -15px; " class="full-width">
<p style="text-indent: -15px; " class="paragraph_style_16"><span style="font-size: 20px; position: relative; top: 3px; " class="Bullet">•</span><span style="width: 8px; " class="inline-block"></span>Minor adjustments to clean up newer compiler warnings<br/></p>
</li>
</ol>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_15">Modifications to unp.h header<br/></p>
<p class="paragraph_style_4"><br/></p>
<ol>
<li style="line-height: 15px; margin-top: -1px; padding-left: 30px; text-indent: -15px; " class="full-width">
<p style="text-indent: -15px; " class="paragraph_style_16"><span style="font-size: 20px; position: relative; top: 3px; " class="Bullet">•</span><span style="width: 8px; " class="inline-block"></span>This header was simplified to contain only what is needed for this example.<br/></p>
</li>
</ol>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">Please note that in these source code examples, certain functions will be capitalized. For example, Fputs() and Writen(). The authors of Unix Network Programming have written custom wrapper functions for normal functions in order to cleanly handle error checking. For a more thorough explanation of this, please see Section 1.4 (page 11) in the Unix Network Programming book.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_3">11.5 Building and Installing wolfSSL<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">Before we begin, download the example code (echoserver and echoclient) from the Getting the Source Code section, above. This section will explain how to download, configure, and install the wolfSSL embedded SSL library on your system.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">You will need to download and install the most recent version of wolfSSL from the wolfSSL<a title="http://wolfssl.com/yaSSL/download/downloadForm.php" href="../../wolfssl.com/yaSSL/download/downloadForm.php"> download page</a>.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">For a full list of available build options, see the<a title="http://www.yassl.com/yaSSL/Docs-cyassl-manual-2-building-cyassl.html" href="../../www.yassl.com/yaSSL/Docs-cyassl-manual-2-building-cyassl.html"> Building wolfSSL</a> guide. wolfSSL was written with portability in mind, and should generally be easy to build on most systems. If you have difficulty building wolfSSL, please feel free to ask for support on the wolfSSL<a title="http://www.wolfssl.com/forums" href="../../www.wolfssl.com/forums"> product support forums</a>.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">When building wolfSSL on Linux, *BSD, OS X, Solaris, or other *nix like systems, you can use the autoconf system. For windows-specific instructions, please refer to the<a title="http://www.yassl.com/yaSSL/Docs-cyassl-manual-2-building-cyassl.html" href="../../www.yassl.com/yaSSL/Docs-cyassl-manual-2-building-cyassl.html"> Building wolfSSL</a> section of the wolfSSL Manual. To configure and build wolfSSL, run the following two commands from the terminal. Any desired build options may be appended to ./configure (ex: ./configure –enable-opensslextra):<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    ./configure<br/></p>
<p class="paragraph_style_14">    make<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">To install wolfSSL, run:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    sudo make install<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">This will install wolfSSL headers into /usr/local/include/wolfssl  and the wolfSSL libraries into /usr/local/lib on your system. To test the build, run the testsuite application from the wolfSSL root directory:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    ./testsuite/testsuite.test<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">A set of tests will be run on wolfCrypt and wolfSSL to verify it has been installed correctly. After a successful run of the testsuite application, you should see output similar to the following:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">MD5      test passed!<br/></p>
<p class="paragraph_style_14">SHA      test passed!<br/></p>
<p class="paragraph_style_14">SHA-224  test passed!<br/></p>
<p class="paragraph_style_14">SHA-256  test passed!<br/></p>
<p class="paragraph_style_14">SHA-384  test passed!<br/></p>
<p class="paragraph_style_14">SHA-512  test passed!<br/></p>
<p class="paragraph_style_14">HMAC-MD5 test passed!<br/></p>
<p class="paragraph_style_14">HMAC-SHA test passed!<br/></p>
<p class="paragraph_style_14">HMAC-SHA224 test passed!<br/></p>
<p class="paragraph_style_14">HMAC-SHA256 test passed!<br/></p>
<p class="paragraph_style_14">HMAC-SHA384 test passed!<br/></p>
<p class="paragraph_style_14">HMAC-SHA512 test passed!<br/></p>
<p class="paragraph_style_14">GMAC     test passed!<br/></p>
<p class="paragraph_style_14">Chacha   test passed!<br/></p>
<p class="paragraph_style_14">POLY1305 test passed!<br/></p>
<p class="paragraph_style_14">ChaCha20-Poly1305 AEAD test passed!<br/></p>
<p class="paragraph_style_14">AES      test passed!<br/></p>
<p class="paragraph_style_14">AES-GCM  test passed!<br/></p>
<p class="paragraph_style_14">RANDOM   test passed!<br/></p>
<p class="paragraph_style_14">RSA      test passed!<br/></p>
<p class="paragraph_style_14">DH       test passed!<br/></p>
<p class="paragraph_style_14">ECC      test passed!<br/></p>
<p class="paragraph_style_14">SSL version is TLSv1.2<br/></p>
<p class="paragraph_style_14">SSL cipher suite is TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384<br/></p>
<p class="paragraph_style_14">SSL version is TLSv1.2<br/></p>
<p class="paragraph_style_14">SSL cipher suite is TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384<br/></p>
<p class="paragraph_style_14">Client message: hello wolfssl!<br/></p>
<p class="paragraph_style_14">Server response: I hear you fa shizzle!<br/></p>
<p class="paragraph_style_14">sending server shutdown command: quit!<br/></p>
<p class="paragraph_style_14">client sent quit command: shutting down!<br/></p>
<p class="paragraph_style_14">ciphers = DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-CHACHA20-POLY1305:DHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305-OLD:ECDHE-ECDSA-CHACHA20-POLY1305-OLD:DHE-RSA-CHACHA20-POLY1305-OLD<br/></p>
<p class="paragraph_style_14">33bc1a4570f4f1abccd5c48aace529b01a42ab51293954a297796e90d20970f0  input<br/></p>
<p class="paragraph_style_14">33bc1a4570f4f1abccd5c48aace529b01a42ab51293954a297796e90d20970f0  /tmp/output-N0Xq9c<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">All tests passed!<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">Now that wolfSSL has been installed, we can begin modifying the example code to add SSL functionality. We will first begin by adding SSL to the echoclient and subsequently move on to the echoserver.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_3">11.6 Initial Compilation<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">To compile and run the example echoclient and echoserver code from the SSL Tutorial source bundle, you can use the included Makefiles. Change directory (cd) to either the echoclient or echoserver directory and run:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    make<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">This will compile the example code and produce an executable named either echoserver or echoclient depending on which one is being built. The GCC command which is used in the Makefile can be seen below. If you want to build one of the examples without using the supplied Makefile, change directory to the example directory and replace tcpcli01.c (echoclient) or tcpserv04.c (echoserver) in the following command with correct source file for the example:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    gcc -o echoserver ../lib/*.c tcpserv04.c -I ../include<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">This will compile the current example into an executable, creating either an “echoserver” or “echoclient” application. To run one of the examples after it has been compiled, change your current directory to the desired example directory and start the application. For example, to start the echoserver use:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    ./echoserver<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">You may open a second terminal window to test the echoclient on your local host and you will need to supply the IP address of the server when starting the application, which in our case will be 127.0.0.1. Change your current directory to the “echoclient” directory and run the following command. Note that the echoserver must already be running:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    ./echoclient 127.0.0.1<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">Once you have both the echoserver and echoclient running, the echoserver should echo back any input that it receives from the echoclient. To exit either the echoserver or echoclient, use [Ctrl + C] to quit the application. Currently, the data being echoed back and forth between these two examples is being sent in the clear - easily allowing anyone with a little bit of skill to inject themselves in between the client and server and listen to your communication.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_3">11.7 Libraries<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">The wolfSSL library, once compiled, is named libwolfssl, and unless otherwise configured the wolfSSL build and install process creates only a shared library under the following directory.  Both shared and static libraries may be enabled or disabled by using the appropriate build options:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    /usr/local/lib<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">The first step we need to do is link the wolfSSL library to our example applications. Modifying the GCC command (using the echoserver as an example), gives us the following new command. Since wolfSSL installs header files and libraries in standard locations, the compiler should be able to find them without explicit instructions (using -l or -L). Note that by using -lwolfssl the compiler will automatically choose the correct type of library (static or shared):<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    gcc -o echoserver ../lib/*.c tcpserv04.c -I ../include -lm -lwolfssl<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_3">11.8 Headers<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">The first thing we will need to do is include the wolfSSL native API header in both the client and the server. In the tcpcli01.c file for the client and the tcpserv04.c file for the server add the following line near the top:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    #include &lt;wolfssl/ssl.h&gt;<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_3">11.9 Startup/Shutdown<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">Before we can use wolfSSL in our code, we need to initialize the library and the WOLFSSL_CTX. wolfSSL is initialized by calling wolfSSL_Init(). This must be done first before anything else can be done with the library.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">The WOLFSSL_CTX structure (wolfSSL Context) contains global values for each SSL connection, including certificate information. A single WOLFSSL_CTX can be used with any number of WOLFSSL objects created. This allows us to load certain information, such as a list of trusted CA certificates only once.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">To create a new WOLFSSL_CTX, use wolfSSL_CTX_new(). This function requires an argument which defines the SSL or TLS protocol for the client or server to use. There are several options for selecting the desired protocol. wolfSSL currently supports SSL 3.0, TLS 1.0, TLS 1.1, TLS 1.2, DTLS 1.0, and DTLS 1.2. Each of these protocols have a corresponding function that can be used as an argument to wolfSSL_CTX_new(). The possible client and server protocol options are shown below. SSL 2.0 is not supported by wolfSSL because it has been insecure for several years.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_15">EchoClient:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    wolfSSLv3_client_method();  // SSL 3.0<br/></p>
<p class="paragraph_style_14">    wolfTLSv1_client_method();  // TLS 1.0<br/></p>
<p class="paragraph_style_14">    wolfTLSv1_1_client_method();// TLS 1.1<br/></p>
<p class="paragraph_style_14">    wolfTLSv1_2_client_method();// TLS 1.2<br/></p>
<p class="paragraph_style_14">    wolfSSLv23_client_method(); // Use highest version possible from TLS 1.0 - TLS 1.2<br/></p>
<p class="paragraph_style_14">    wolfDTLSv1_client_method();    // DTLS 1.0<br/></p>
<p class="paragraph_style_14">    wolfDTLSv1_2_client_method();  // DTLS 1.2<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_15">EchoServer:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    wolfSSLv3_server_methods(); // SSLv3<br/></p>
<p class="paragraph_style_14">    wolfTLSv1_server_method();  // TLSv1<br/></p>
<p class="paragraph_style_14">    wolfTLSv1_1_server_method();// TLSv1.1<br/></p>
<p class="paragraph_style_14">    wolfTLSv1_2_server_method();// TLSv1.2<br/></p>
<p class="paragraph_style_14">    wolfSSLv23_server_method(); // Allow clients to connect with TLSv1+<br/></p>
<p class="paragraph_style_14">    wolfDTLSv1_server_method(); // DTLS<br/></p>
<p class="paragraph_style_14">    wolfDTLSv1_2_server_method();  // DTLS 1.2<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">We need to load our CA (Certificate Authority) certificate into the WOLFSSL_CTX so that the when the echoclient connects to the echoserver, it is able to verify the server’s identity. To load the CA certificates into the WOLFSSL_CTX, use wolfSSL_CTX_load_verify_locations(). This function requires three arguments: a WOLFSSL_CTX pointer, a certificate file, and a path value. The path value points to a directory which should contain CA certificates in PEM format. When looking up certificates, wolfSSL will look at the certificate file value before looking in the path location. In this case, we don’t need to specify a certificate path because we will specify one CA file - as such we use the value 0 for the path argument. The wolfSSL_CTX_load_verify_locations function returns either SSL_SUCCESS or SSL_FAILURE:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    wolfSSL_CTX_load_verify_locations(WOLFSSL_CTX* ctx, const char* file,<br/></p>
<p class="paragraph_style_14">                                     const char* path)<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">Putting these things together (library initialization, protocol selection, and CA certificate), we have the following. Here, we choose to use TLS 1.2:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_15">EchoClient:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">     WOLFSSL_CTX* ctx;<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">    wolfSSL_Init();// Initialize wolfSSL<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">    /* Create the WOLFSSL_CTX */<br/></p>
<p class="paragraph_style_14">    if ( (ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method())) == NULL){<br/></p>
<p class="paragraph_style_14">        fprintf(stderr, &quot;wolfSSL_CTX_new error.\n&quot;);<br/></p>
<p class="paragraph_style_14">        exit(EXIT_FAILURE);<br/></p>
<p class="paragraph_style_14">    }<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">    /* Load CA certificates into WOLFSSL_CTX */<br/></p>
<p class="paragraph_style_14">    if (wolfSSL_CTX_load_verify_locations(ctx,&quot;../certs/ca-cert.pem&quot;,0) !=<br/></p>
<p class="paragraph_style_14">        SSL_SUCCESS) {<br/></p>
<p class="paragraph_style_14">        fprintf(stderr, &quot;Error loading ../certs/ca-cert.pem, please check<br/></p>
<p class="paragraph_style_14">            the file.\n&quot;);<br/></p>
<p class="paragraph_style_14">        exit(EXIT_FAILURE);<br/></p>
<p class="paragraph_style_14">    }<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_15">EchoServer:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">When loading certificates into the WOLFSSL_CTX, the server certificate and key file should be loaded in addition to the CA certificate. This will allow the server to send the client its certificate for identification verification:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    WOLFSSL_CTX* ctx;<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">    wolfSSL_Init();// Initialize wolfSSL<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">    /* Create the WOLFSSL_CTX */<br/></p>
<p class="paragraph_style_14">    if ( (ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method())) == NULL){<br/></p>
<p class="paragraph_style_14">        fprintf(stderr, &quot;wolfSSL_CTX_new error.\n&quot;);<br/></p>
<p class="paragraph_style_14">        exit(EXIT_FAILURE);<br/></p>
<p class="paragraph_style_14">    }<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">    /* Load CA certificates into CYASSL_CTX */<br/></p>
<p class="paragraph_style_14">    if (wolfSSL_CTX_load_verify_locations(ctx, &quot;../certs/ca-cert.pem&quot;, 0) !=<br/></p>
<p class="paragraph_style_14">            SSL_SUCCESS) {<br/></p>
<p class="paragraph_style_14">        fprintf(stderr, &quot;Error loading ../certs/ca-cert.pem, &quot;<br/></p>
<p class="paragraph_style_14">            &quot;please check the file.\n&quot;);<br/></p>
<p class="paragraph_style_14">        exit(EXIT_FAILURE);<br/></p>
<p class="paragraph_style_14">    }<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">    /* Load server certificates into WOLFSSL_CTX */<br/></p>
<p class="paragraph_style_14">    if (wolfSSL_CTX_use_certificate_file(ctx,&quot;../certs/server-cert.pem&quot;,<br/></p>
<p class="paragraph_style_14">            SSL_FILETYPE_PEM) != SSL_SUCCESS){<br/></p>
<p class="paragraph_style_14">        fprintf(stderr, &quot;Error loading ../certs/server-cert.pem, please “<br/></p>
<p class="paragraph_style_14">            “check the file.\n&quot;);<br/></p>
<p class="paragraph_style_14">        exit(EXIT_FAILURE);<br/></p>
<p class="paragraph_style_14">    }<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">    /* Load keys */<br/></p>
<p class="paragraph_style_14">    if (wolfSSL_CTX_use_PrivateKey_file(ctx,&quot;../certs/server-key.pem&quot;,<br/></p>
<p class="paragraph_style_14">            SSL_FILETYPE_PEM) != SSL_SUCCESS){<br/></p>
<p class="paragraph_style_14">        fprintf(stderr, &quot;Error loading ../certs/server-key.pem, please check “<br/></p>
<p class="paragraph_style_14">            “the file.\n&quot;);<br/></p>
<p class="paragraph_style_14">        exit(EXIT_FAILURE);<br/></p>
<p class="paragraph_style_14">    }<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">The code shown above should be added to the beginning of tcpcli01.c and tcpserv04.c, after both the variable definitions and the check that the user has started the client with an IP address (client). A version of the finished code is included in the SSL tutorial ZIP file for reference.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">Now that wolfSSL and the WOLFSSL_CTX have been initialized, make sure that the WOLFSSL_CTX object and the wolfSSL library are freed when the application is completely done using SSL/TLS. In both the client and the server, the following two lines should be placed at the end of the main() function (in the server right before the call to exit() ):<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    wolfSSL_CTX_free(ctx);<br/></p>
<p class="paragraph_style_14">    wolfSSL_Cleanup();<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_3">11.10 WOLFSSL Object<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_15">EchoClient<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">A WOLFSSL object needs to be created after each TCP Connect and the socket file descriptor needs to be associated with the session. In the echoclient example, we will do this after the call to Connect(), shown below:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    /* Connect to socket file descriptor */<br/></p>
<p class="paragraph_style_14">    Connect(sockfd, (SA *) &amp;servaddr, sizeof(servaddr));<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">Directly after connecting, create a new WOLFSSL object using the wolfSSL_new() function. This function returns a pointer to the WOLFSSL object if successful or NULL in the case of failure. We can then associate the socket file descriptor (sockfd) with the new WOLFSSL object (ssl):<br/></p>
<p class="paragraph_style_14">    <br/></p>
<p class="paragraph_style_14">    /* Create WOLFSSL object */<br/></p>
<p class="paragraph_style_14">    WOLFSSL* ssl;<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">    if( (ssl = wolfSSL_new(ctx)) == NULL) {<br/></p>
<p class="paragraph_style_14">       fprintf(stderr, &quot;wolfSSL_new error.\n&quot;);<br/></p>
<p class="paragraph_style_14">       exit(EXIT_FAILURE);<br/></p>
<p class="paragraph_style_14">    }<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">    wolfSSL_set_fd(ssl, sockfd);<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">One thing to notice here is we haven’t made a call to the wolfSSL_connect() function. wolfSSL_connect() initiates the SSL/TLS handshake with the server, and is called during wolfSSL_read() if it hasn’t been called previously. In our case, we don’t explicitly call wolfSSL_connect(), as we let our first wolfSSL_read() do it for us.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_15">EchoServer<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">At the end of the for loop in the main method, insert the WOLFSSL object and associate the socket file descriptor (connfd) with the WOLFSSL object (ssl), just as with the client:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><span class="style_6">    /* Create WOLFSSL object */<br/></span></p>
<p class="paragraph_style_4"><span class="style_6">    WOLFSSL* ssl;<br/></span></p>
<p class="paragraph_style_4"><span class="style_6">  <br/></span></p>
<p class="paragraph_style_4"><span class="style_6">    if ( (ssl = wolfSSL_new(ctx)) == NULL) {                     <br/></span></p>
<p class="paragraph_style_4"><span class="style_6">        fprintf(stderr, &quot;wolfSSL_new error.\n&quot;);                 <br/></span></p>
<p class="paragraph_style_4"><span class="style_6">        exit(EXIT_FAILURE);                                     <br/></span></p>
<p class="paragraph_style_4"><span class="style_6">    }                                                          <br/></span></p>
<p class="paragraph_style_4"><span class="style_6">                                                                           <br/></span></p>
<p class="paragraph_style_4"><span class="style_6">    wolfSSL_set_fd(ssl, connfd);      </span>                          <br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">A WOLFSSL object needs to be created after each TCP Connect and the socket file descriptor needs to be associated with the session. <br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">Create a new WOLFSSL object using the <span class="style_1">wolfSSL_new</span>() function. This function returns a pointer to the WOLFSSL object if successful or NULL in the case of failure. We can then associate the socket file descriptor (<span class="style_1">sockfd</span>) with the new WOLFSSL object (<span class="style_1">ssl</span>):<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    /* Create WOLFSSL object */<br/></p>
<p class="paragraph_style_14">    WOLFSSL* ssl;<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">    if( (ssl = wolfSSL_new(ctx)) == NULL) {<br/></p>
<p class="paragraph_style_14">        fprintf(stderr, &quot;wolfSSL_new error.\n&quot;);<br/></p>
<p class="paragraph_style_14">        exit(EXIT_FAILURE);<br/></p>
<p class="paragraph_style_14">    }<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">    wolfSSL_set_fd(ssl, sockfd);<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_3">11.11 Sending/Receiving Data<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_15">EchoClient<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">The next step is to begin sending data securely. Take note that in the echoclient example, the main() function hands off the sending and receiving work to str_cli(). The str_cli() function is where our function replacements will be made. First we need access to our WOLFSSL object in the str_cli() function, so we add another argument and pass the ssl variable to str_cli(). Because the WOLFSSL object is now going to be used inside of the str_cli() function, we remove the sockfd parameter. The new str_cli() function signature after this modification is shown below:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    void str_cli(FILE *fp, WOLFSSL* ssl)<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">In the main() function, the new argument (ssl) is passed to str_cli():<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    str_cli(stdin, ssl);<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">Inside the str_cli() function, Writen() and Readline() are replaced with calls to wolfSSL_write() and wolfSSL_read()  functions, and the WOLFSSL object (ssl) is used instead of the original file descriptor(sockfd). The new str_cli() function is shown below. Notice that we now need to check if our calls to wolfSSL_write and wolfSSL_read were successful.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">The authors of the Unix Programming book wrote error checking into their Writen() function which we must make up for after it has been replaced. We add a new int variable, “n”, to monitor the return value of wolfSSL_read and before printing out the contents of the buffer, recvline, the end of our read data is marked with a ‘\0’:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    void<br/></p>
<p class="paragraph_style_14">    str_cli(FILE *fp, WOLFSSL* ssl)<br/></p>
<p class="paragraph_style_14">    {<br/></p>
<p class="paragraph_style_14">        char  sendline[MAXLINE], recvline[MAXLINE];<br/></p>
<p class="paragraph_style_14">        int   n = 0;<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">        while (Fgets(sendline, MAXLINE, fp) != NULL) {<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">            if(wolfSSL_write(ssl, sendline, strlen(sendline)) !=<br/></p>
<p class="paragraph_style_14">                      strlen(sendline)){<br/></p>
<p class="paragraph_style_14">                err_sys(&quot;wolfSSL_write failed&quot;);<br/></p>
<p class="paragraph_style_14">            }<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">            if ((n = wolfSSL_read(ssl, recvline, MAXLINE)) &lt;= 0)<br/></p>
<p class="paragraph_style_14">                err_quit(&quot;wolfSSL_read error&quot;);<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">            recvline[n] = '\0';<br/></p>
<p class="paragraph_style_14">            Fputs(recvline, stdout);<br/></p>
<p class="paragraph_style_14">        }<br/></p>
<p class="paragraph_style_14">    }<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">The last thing to do is free the WOLFSSL object when we are completely done with it. In the main() function, right before the line to free the WOLFSSL_CTX, call to wolfSSL_free():<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    str_cli(stdin, ssl);<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">    wolfSSL_free(ssl);     /* Free WOLFSSL object */<br/></p>
<p class="paragraph_style_14">    wolfSSL_CTX_free(ctx); /* Free WOLFSSL_CTX object */<br/></p>
<p class="paragraph_style_14">    wolfSSL_Cleanup();     /* Free wolfSSL */<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_15">EchoServer<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">The echo server makes a call to str_echo() to handle reading and writing (whereas the client made a call to str_cli()). As with the client, modify str_echo() by replacing the sockfd parameter with a WOLFSSL object (ssl) parameter in the function signature:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    void str_echo(WOLFSSL* ssl)<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">Replace the calls to Read() and Writen() with calls to the wolfSSL_read() and wolfSSL_write() functions. The modified str_echo() function, including error checking of return values, is shown below. Note that the type of the variable “n” has been changed from ssize_t to int in order to accommodate for the change from read() to wolfSSL_read():<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    void<br/></p>
<p class="paragraph_style_14">    str_echo(WOLFSSL* ssl)<br/></p>
<p class="paragraph_style_14">    {<br/></p>
<p class="paragraph_style_14">        int n;<br/></p>
<p class="paragraph_style_14">        char buf[MAXLINE];<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">        while ( (n = wolfSSL_read(ssl, buf, MAXLINE)) &gt; 0) {<br/></p>
<p class="paragraph_style_14">            if(wolfSSL_write(ssl, buf, n) != n) {<br/></p>
<p class="paragraph_style_14">                err_sys(&quot;wolfSSL_write failed&quot;);<br/></p>
<p class="paragraph_style_14">            }<br/></p>
<p class="paragraph_style_14">        }<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">        if( n &lt; 0 )<br/></p>
<p class="paragraph_style_14">            printf(&quot;wolfSSL_read error = %d\n&quot;, wolfSSL_get_error(ssl,n));<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">        else if( n == 0 )<br/></p>
<p class="paragraph_style_14">            printf(&quot;The peer has closed the connection.\n&quot;);<br/></p>
<p class="paragraph_style_14">    }<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">In main() call the str_echo() function at the end of the for loop (soon to be changed to a while loop). After this function, inside the loop, make calls to free the WOLFSSL object and close the connfd socket:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">str_echo(ssl);        /* process the request */<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">wolfSSL_free(ssl);    /* Free WOLFSSL object */<br/></p>
<p class="paragraph_style_14">Close(connfd);<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">We will free the ctx and cleanup before the call to exit.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_3">11.12 Signal Handling<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_15">Echoclient / Echoserver<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">In the echoclient and echoserver, we will need to add a signal handler for when the user closes the app by using “Ctrl+C”. The echo server is continually running in a loop. Because of this, we need to provide a way to break that loop when the user presses “Ctrl+C”. To do this, the first thing we need to do is change our loop to a while loop which terminates when an exit variable (cleanup) is set to true.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">First, define a new static int variable called cleanup at the top of tcpserv04.c right after the #include statements:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    static int cleanup;  /* To handle shutdown */<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">Modify the echoserver loop by changing it from a for loop to a while loop:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    while(cleanup != 1)<br/></p>
<p class="paragraph_style_14">    {<br/></p>
<p class="paragraph_style_14">        /* echo server code here */<br/></p>
<p class="paragraph_style_14">    }<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">For the echoserver we need to disable the operating system from restarting calls which were being executed before the signal was handled after our handler has finished. By disabling these, the operating system will not restart calls to accept() after the signal has been handled. If we didn’t do this, we would have to wait for another client to connect and disconnect before the echoserver would clean up resources and exit. To define the signal handler and turn off SA_RESTART, first define act and oact structures in the echoserver’s main() function:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    struct sigaction     act, oact;<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">Insert the following code after variable declarations, before the call to wolfSSL_Init() in the main function:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    /* Define a signal handler for when the user closes the program<br/></p>
<p class="paragraph_style_14"> with Ctrl-C. Also, turn off SA_RESTART so that the OS doesn't<br/></p>
<p class="paragraph_style_14"> restart the call to accept()after the signal is handled. */<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">    act.sa_handler = sig_handler;<br/></p>
<p class="paragraph_style_14">    sigemptyset(&amp;act.sa_mask);<br/></p>
<p class="paragraph_style_14">    act.sa_flags = 0;<br/></p>
<p class="paragraph_style_14">    sigaction(SIGINT, &amp;act, &amp;oact);<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">The echoserver’s sig_handler function is shown below:<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_14">    void sig_handler(const int sig)<br/></p>
<p class="paragraph_style_14">    {<br/></p>
<p class="paragraph_style_14">        printf(&quot;\nSIGINT handled.\n&quot;);<br/></p>
<p class="paragraph_style_14">        cleanup = 1;<br/></p>
<p class="paragraph_style_14">        return;<br/></p>
<p class="paragraph_style_14">    }<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">That’s it - the echoclient and echoserver are now enabled with TLSv1.2!!<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">What we did:<br/></p>
<ol>
<li style="line-height: 15px; padding-left: 15px; text-indent: -15px; " class="full-width">
<p style="text-indent: -15px; " class="paragraph_style_18"><span style="font-size: 12px; " class="Bullet">•</span><span style="width: 11px; " class="inline-block"></span>Included the wolfSSL headers<br/></p>
</li>
<li style="line-height: 15px; padding-left: 15px; text-indent: -15px; " class="full-width">
<p style="text-indent: -15px; " class="paragraph_style_18"><span style="font-size: 12px; " class="Bullet">•</span><span style="width: 11px; " class="inline-block"></span>Initialized wolfSSL<br/></p>
</li>
<li style="line-height: 15px; padding-left: 15px; text-indent: -15px; " class="full-width">
<p style="text-indent: -15px; " class="paragraph_style_18"><span style="font-size: 12px; " class="Bullet">•</span><span style="width: 11px; " class="inline-block"></span>Created a WOLFSSL_CTX structure in which we chose what protocol we wanted to use<br/></p>
</li>
<li style="line-height: 15px; padding-left: 15px; text-indent: -15px; " class="full-width">
<p style="text-indent: -15px; " class="paragraph_style_18"><span style="font-size: 12px; " class="Bullet">•</span><span style="width: 11px; " class="inline-block"></span>Created a WOLFSSL object to use for sending and receiving data<br/></p>
</li>
<li style="line-height: 15px; padding-left: 15px; text-indent: -15px; " class="full-width">
<p style="text-indent: -15px; " class="paragraph_style_18"><span style="font-size: 12px; " class="Bullet">•</span><span style="width: 11px; " class="inline-block"></span>Replaced calls to Writen() and Readline() with wolfSSL_write() and wolfSSL_read()<br/></p>
</li>
<li style="line-height: 15px; padding-left: 15px; text-indent: -15px; " class="full-width">
<p style="text-indent: -15px; " class="paragraph_style_18"><span style="font-size: 12px; " class="Bullet">•</span><span style="width: 11px; " class="inline-block"></span>Freed WOLFSSL, WOLFSSL_CTX<br/></p>
</li>
<li style="line-height: 15px; padding-left: 15px; text-indent: -15px; " class="full-width">
<p style="text-indent: -15px; " class="paragraph_style_18"><span style="font-size: 12px; " class="Bullet">•</span><span style="width: 11px; " class="inline-block"></span>Made sure we handled client and server shutdown with signal handler<br/></p>
</li>
</ol>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">There are many more aspects and methods to configure and control the behavior of your SSL connections. For more detailed information, please see additional wolfSSL documentation and resources.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">Once again, the completed source code can be found in the downloaded ZIP file at the top of this section.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_3">11.13 Certificates<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">For testing purposes, you may use the certificates provided by wolfSSL. These can be found in the wolfSSL download, and specifically for this tutorial, they can be found in the <span class="style_1">finished_src</span> folder.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">For production applications, you should obtain correct and legitimate certificates from a trusted certificate authority.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_3">11.14 Conclusion<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">This tutorial walked through the process of integrating the wolfSSL embedded SSL library into a simple client and server application. Although this example is simple, the same principles may be applied for adding SSL or TLS into your own application. The wolfSSL embedded SSL library provides all the features you would need in a compact and efficient package that has been optimized for both size and speed.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p class="paragraph_style_4">Being dual licensed under GPLv2 and standard commercial licensing, you are free to download the wolfSSL source code directly from our website. Feel free to post to our support forums (<a title="http://www.wolfssl.com/forums" href="../../www.wolfssl.com/forums">www.wolfssl.com/forums</a>) with any questions or comments you might have. If you would like more information about our products, please contact <a title="mailto:info@wolfssl.com" href="../cdn-cgi/l/email-protection#81e8efe7eec1f6eeede7f2f2edafe2eeec"><span class="__cf_email__" data-cfemail="90f9fef6ffd0e7fffcf6e3e3fcbef3fffd">[email&#160;protected]</span><script data-cfhash='f9e31' type="text/javascript">/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */</script></a>.<br/></p>
<p class="paragraph_style_4"><br/></p>
<p style="padding-bottom: 0pt; " class="paragraph_style_4">We welcome any feedback you have on this SSL tutorial. If you believe it could be improved or enhanced in order to make it either more useful, easier to understand, or more portable, please let us know at <a title="mailto:support@yassl.com" href="../cdn-cgi/l/email-protection#25565055554a5751655c445656490b464a48"><span class="__cf_email__" data-cfemail="d4a7a1a4a4bba6a094a3bbb8b2a7a7b8fab7bbb9">[email&#160;protected]</span><script data-cfhash='f9e31' type="text/javascript">/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */</script></a>.</p>
</div>
</div>
</div>
<div id="id20" style="height: 25px; left: 323px; position: absolute; top: 224px; width: 125px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_125_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_19"><a title="Docs-wolfssl-manual-toc.html" href="Docs-wolfssl-manual-toc.html">Table of Contents</a></p>
</div>
</div>
</div>
<div style="height: 16px; width: 20px;  height: 16px; left: 706px; position: absolute; top: 51px; width: 20px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 20px; ">
<img src="Docs-wolfssl-manual-11-ssl-tutorial_files/shapeimage_11.png" alt="" style="height: 16px; left: 0px; position: absolute; top: 0px; width: 20px; "/>
</div>
</div>
<div style="height: 19px; width: 19px;  height: 19px; left: 707px; position: absolute; top: 25px; width: 19px; z-index: 1; " class="tinyText style_SkipStroke_2">
<img src="Docs-wolfssl-manual-11-ssl-tutorial_files/United%20Kingdom%28Great%20Britain%29.png" alt="" style="border: none; height: 19px; width: 19px; "/>
</div>
<div id="id21" style="height: 23px; left: 328px; position: absolute; top: 48px; width: 258px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_258_23" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_20">Questions? +1 (425) 245-8247</p>
</div>
</div>
</div>
<div style="height: 19px; width: 19px;  height: 19px; left: 685px; position: absolute; top: 25px; width: 19px; z-index: 1; " class="tinyText style_SkipStroke_2">
<a href="../../www.wolfssl.jp/default.htm" title="http://www.wolfssl.jp"><img src="Docs-wolfssl-manual-11-ssl-tutorial_files/japan.png" alt="" style="border: none; height: 19px; width: 19px; "/></a>
</div>
<div id="id22" style="height: 28px; left: 593px; position: absolute; top: 44px; width: 119px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_119_28" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_21"><a class="class15" title="https://www.wolfssl.com/forums" href="../forums">Support <span class="style_7">Forums</span></a></p>
</div>
</div>
</div>
<div style="height: 112px; width: 183px;  height: 112px; left: -1px; position: absolute; top: 7px; width: 183px; z-index: 1; " class="tinyText style_SkipStroke_2">
<a href="Home.html" title="Home.html"><img src="Docs-wolfssl-manual-11-ssl-tutorial_files/wolf-christmas.png" alt="" style="border: none; height: 112px; width: 183px; "/></a>
</div>
<div style="height: 10102px; line-height: 10102px; " class="spacer"> </div>
</div>
<div style="height: 100px; margin-left: 0px; position: relative; width: 770px; z-index: 15; " id="footer_layer">
<div style="height: 0px; line-height: 0px; " class="bumper"> </div>
<div id="id23" style="height: 27px; left: 634px; position: absolute; top: 27px; width: 102px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_102_27" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_8"><a class="class16" title="Docs-wolfssl-manual-12-best-practices-for-embedded-devices.html" href="Docs-wolfssl-manual-12-best-practices-for-embedded-devices.html">Next Chapter</a></p>
</div>
</div>
</div>
<div id="id24" style="height: 25px; left: 35px; position: absolute; top: 27px; width: 125px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_125_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_22"><a class="class17" title="Docs-wolfssl-manual-10-wolfcrypt-usage-reference.html" href="Docs-wolfssl-manual-10-wolfcrypt-usage-reference.html">Previous Chapter</a></p>
</div>
</div>
</div>
<div id="id25" style="height: 25px; left: 323px; position: absolute; top: 27px; width: 125px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_125_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_19"><a class="class18" title="Docs-wolfssl-manual-toc.html" href="Docs-wolfssl-manual-toc.html">Table of Contents</a></p>
</div>
</div>
</div>
<div id="id26" style="height: 29px; left: 35px; position: absolute; top: 65px; width: 701px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_701_29" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_23">Copyright 2016 wolfSSL Inc.  All rights reserved.</p>
</div>
</div>
</div>
</div>
</div>
</div>
 <script type="text/javascript">/* <![CDATA[ */(function(d,s,a,i,j,r,l,m,t){try{l=d.getElementsByTagName('a');t=d.createElement('textarea');for(i=0;l.length-i;i++){try{a=l[i].href;s=a.indexOf('/cdn-cgi/l/email-protection');m=a.length;if(a&&s>-1&&m>28){j=28+s;s='';if(j<m){r='0x'+a.substr(j,2)|0;for(j+=2;j<m&&a.charAt(j)!='X';j+=2)s+='%'+('0'+('0x'+a.substr(j,2)^r).toString(16)).slice(-2);j++;s=decodeURIComponent(s)+a.substr(j,m-j)}t.innerHTML=s.replace(/</g,'&lt;').replace(/>/g,'&gt;');l[i].href='mailto:'+t.value}}catch(e){}}}catch(e){}})(document);/* ]]> */</script></body>
</html>
